package com.zjp.demo02251.controller;

import com.zjp.demo02251.dao.CompanyUser;
import com.zjp.demo02251.dao.Result;
import com.zjp.demo02251.enums.ResultEnum;
import com.zjp.demo02251.service.CompanyUserService;
import com.zjp.demo02251.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author james
 * @Title: CompanyUserController
 * @Package com.zjp.demo02251.controller
 * @Description:
 * @date 2018/2/25  19:07
 */
@RestController
public class CompanyUserController {

    @Autowired
    private CompanyUserService companyUserService;

    /**
     * @Description: 查询所有员工
     * @author james
     * @date 2018/2/25  19:08
    */
    @GetMapping(value = "/findall")
    public Result<CompanyUser> findALLCompanyUser() throws Exception{

        if(companyUserService.getALLCompanyUser()==null){
            ResultUtil.error(ResultEnum.UNKONW_ERROR);
        }
       return ResultUtil.success(companyUserService.getALLCompanyUser());

    }

    /**
     * @Description: 根据id查询员工
     * @author james
     * @param
     * @return
     * @date 2018/2/25  21:30
    */
    @GetMapping("/findid/{id}")
    public Result<CompanyUser> findById(@PathVariable(value = "id") Integer id ) throws  Exception{
        return ResultUtil.success(companyUserService.getUserById(id));
    }

}
